package com.prs.crm.domain.flow;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.prs.crm.domain.BaseEntity;
import com.prs.crm.domain.hr.Person;

/**
 * 流程运行实例
 * @author Administrator
 *
 */
@Entity
@Table(name="flow_process")
@MappedSuperclass
public  class WorkFlowProcess extends BaseEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3727661016407069395L;

	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	@ManyToOne
	private WorkFlowInstance instance;
	
	@ManyToOne(fetch=FetchType.LAZY)
	private Person initiator;
	/*开始时间*/
	private Date startTime;
	/*结束时间*/
	private Date endTime;
	
	@OneToMany(cascade = CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="flowProcess")
	@OrderBy
	private Set<WorkFlowProcessNode> processNodes;
	
	private Integer status;
	
	private Integer result;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setInstance(WorkFlowInstance instance) {
		this.instance = instance;
	}

	public WorkFlowInstance getInstance() {
		return instance;
	}

	public void setInitiator(Person initiator) {
		this.initiator = initiator;
	}

	public Person getInitiator() {
		return initiator;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getStatus() {
		return status;
	}

	public void setProcessNodes(Set<WorkFlowProcessNode> processNodes) {
		this.processNodes = processNodes;
	}

	public Set<WorkFlowProcessNode> getProcessNodes() {
		return processNodes;
	}
	
	public void addNode(WorkFlowProcessNode processNode)
	{
		if (processNodes==null)
		{
			processNodes = new HashSet<WorkFlowProcessNode>();
		}
		processNodes.add(processNode);
	}

	public void setResult(Integer result) {
		this.result = result;
	}

	public Integer getResult() {
		return result;
	}




	
	
}
